/*
 *  Copyright [2012] Paulo de Tarso
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package revendedora.entidades;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.persistence.*;

/**
 *
 * @author Tarso
 */
@Entity
@Table(name="TB_CAMPANHA",schema="REVENDAAVON")
public class Campanha implements Serializable, Comparable<Campanha> {
    private static final long serialVersionUID = -929057466464616339L;
    
    @Id @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;
    
    @Column(name="CODIGO_CAMPANHA", length=7, nullable=false)
    private String codigoCampanha;
    
    @OneToMany(cascade= CascadeType.MERGE, mappedBy="campanhaReferente")
    private List<ItemCampanha> itensRevendidos;

    @Column(name="DATA_INICIAL", nullable=true)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataInicial;
    
    @Column(name="DATA_FINAL", nullable=true)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataFinal;
    
    public Campanha() {
        this(0l, null, null, null, null);
    }

    public Campanha(Long id, String codigoCampanha, List<ItemCampanha> itensRevendidos, Date dataInicial, Date dtaFinal) {
        this.id = id;
        this.codigoCampanha = codigoCampanha;
        this.itensRevendidos = itensRevendidos;
        this.dataInicial = dataInicial;
        this.dataFinal = dataFinal;
    }

    @Override
    public int compareTo(Campanha o) {
        return this.compareTo(o);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Campanha other = (Campanha) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.codigoCampanha, other.codigoCampanha)) {
            return false;
        }
        if (!Objects.equals(this.itensRevendidos, other.itensRevendidos)) {
            return false;
        }
        if (!Objects.equals(this.dataInicial, other.dataInicial)) {
            return false;
        }
        if (!Objects.equals(this.dataFinal, other.dataFinal)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + Objects.hashCode(this.id);
        hash = 59 * hash + Objects.hashCode(this.codigoCampanha);
        hash = 59 * hash + Objects.hashCode(this.itensRevendidos);
        hash = 59 * hash + Objects.hashCode(this.dataInicial);
        hash = 59 * hash + Objects.hashCode(this.dataFinal);
        return hash;
    }

    @Override
    public String toString() {
        return "Campanha{" + "id=" + id + ", codigoCampanha=" + codigoCampanha + ", itensRevendidos=" + itensRevendidos + ", dataInicial=" + dataInicial + ", dataFinal=" + dataFinal + '}';
    }

    public String getCodigoCampanha() {
        return codigoCampanha;
    }

    public void setCodigoCampanha(String codigoCampanha) {
        this.codigoCampanha = codigoCampanha;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<ItemCampanha> getItensRevendidos() {
        return itensRevendidos;
    }

    public void setItensRevendidos(List<ItemCampanha> itensRevendidos) {
        this.itensRevendidos = itensRevendidos;
    }

    public Date getDataFinal() {
        return dataFinal;
    }

    public void setDataFinal(Date dataFinal) {
        this.dataFinal = dataFinal;
    }

    public Date getDataInicial() {
        return dataInicial;
    }

    public void setDataInicial(Date dataInicial) {
        this.dataInicial = dataInicial;
    }
}
